要在自己的缓冲区中编辑Lisp代码,请创建一个缓冲区,并将其命名为 mycode.el
. 要确保Emacs意识到您正在编辑Lisp,您可以输入=M-x lisp-mode=.
您现在应该在屏幕底部的状态行上看到 (Lisp)
了.现在输入代码。满意后,输入 M-x eval-buffer
将代码在Emacs中运行。
然后创建另一个测试缓冲区(就如 上一个例子中 开头所说的,输入 C-x 5 b
),在其中运行代码。
在测试缓冲区中,键入 M-:
可以在窗口底部得到Lisp提示符,然后通过在括号中键入函数名称来运行。
(defun drawxy (x y sprite)
(erase-buffer)
(dotimes (j y)
(newline))
(dotimes (i x)
(insert " "))
(insert sprite))
sprite
是要绘制的文本。
(defun liner ()
(dotimes (x 20)
(drawxy x x "!")
(sit-for 0.1)))
(defun oVeR-sine ()
(dotimes (y 777)
(erase-buffer)
(drawxy (round (+ 10 (* 10 (sin (/ y 10.0)))))
(round (+ 10 (* 10 (sin (/ y 13.0)))))
"--->)")
(sit-for 0.1)))
(defun background (width height)
(erase-buffer)
(dotimes (i height)
(dotimes (j width)
(insert "."))
(newline)))
(defun drawxy2 (x y sprite)
(goto-char (point-min))
(forward-line y)
(forward-char x)
(delete-region (point) (+ (point) (length sprite)))
(insert sprite))
(defun liner2 ()
(background 80 40)
(dotimes (x 20)
(drawxy2 x x "&")
(drawxy2 (- 20 x) x "*")
(sit-for 0.1)))
(insert (propertize "foreground color test" 'face '(:foreground "red"))) (insert (propertize "gray background test" 'face '(:background "gray30"))) (insert (propertize "color with hex code" 'face '(:foreground "#33AAFF"))) (insert (propertize "lots of color" 'face '(:foreground "orange" :background "purple")))
要在 ielm
上着色,首先输入 M-x font-lock-mode
. 你应该在屏幕底部看到一条消息 Font-Lock mode disabled
(如果它说的是 enabled
, 那么再输入一次 M-x Font-Lock -mode
)。
或者你在创建test试缓冲区中工作就好了。